struct VertexToPixel
{
    float4 Position   	: POSITION;    
    float2 TextureCoords: TEXCOORD0;
	float2 MixCoords: TEXCOORD1;
};

float4x4 Projection;
float4x4 LandscapeToScreen;

float ViewportWidth;
float ViewportHeight;

float ShiftX;
float ShiftY;

Texture LandTexture1;
Texture LandTexture2;
Texture LandTexture3;
Texture LandTexture4;
Texture LandTexture5;
Texture LandTexture6;
Texture MixTexture1;
Texture MixTexture2;

sampler LandTexture1Sampler = 
sampler_state 
{ 
texture = <LandTexture1>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler LandTexture2Sampler = 
sampler_state 
{ 
texture = <LandTexture2>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler LandTexture3Sampler = 
sampler_state 
{ 
texture = <LandTexture3>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler LandTexture4Sampler = 
sampler_state 
{ 
texture = <LandTexture4>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler LandTexture5Sampler = 
sampler_state 
{ 
texture = <LandTexture5>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler LandTexture6Sampler = 
sampler_state 
{ 
texture = <LandTexture6>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler MixTexture1Sampler = 
sampler_state 
{ 
texture = <MixTexture1>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

sampler MixTexture2Sampler = 
sampler_state 
{ 
texture = <MixTexture2>; 
magfilter = LINEAR; 
minfilter = LINEAR; 
mipfilter = LINEAR; 
AddressU = mirror; 
AddressV = mirror;
};

struct PixelToFrame
{
    float4 Color : COLOR0;
};

//------- Technique: Landscape --------

VertexToPixel LandscapeVS( float4 inPos : POSITION, float2 inTexCoords: TEXCOORD0, float2 mixTexCoords: TEXCOORD1)
{	
	VertexToPixel Output = (VertexToPixel)0;

	Output.Position = mul(inPos,LandscapeToScreen);
	Output.Position.x += ShiftX;
	Output.Position.y += ShiftY;
	Output.Position = mul(Output.Position,Projection);
	Output.Position.z = inPos.z;
	Output.TextureCoords = inTexCoords;
	Output.MixCoords = mixTexCoords;
    
	return Output;    
}

PixelToFrame LandscapePS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;		
	
	float4 color1 = tex2D(LandTexture1Sampler,PSIn.TextureCoords.xy);
	float4 color2 = tex2D(LandTexture2Sampler,PSIn.TextureCoords.xy);
	float4 color3 = tex2D(LandTexture3Sampler,PSIn.TextureCoords.xy);
	float4 color4 = tex2D(LandTexture4Sampler,PSIn.TextureCoords.xy);
	float4 color5 = tex2D(LandTexture5Sampler,PSIn.TextureCoords.xy);
	float4 color6 = tex2D(LandTexture6Sampler,PSIn.TextureCoords.xy);
	float4 mixcolor1 = tex2D(MixTexture1Sampler,PSIn.MixCoords.xy);
	float4 mixcolor2 = tex2D(MixTexture2Sampler,PSIn.MixCoords.xy);

	Output.Color = (color1 * mixcolor1.r + color2 * mixcolor1.g + color3 * mixcolor1.b + color4 * mixcolor2.r + color5 * mixcolor2.g + color6 * mixcolor2.b);
	
	return Output;
}

technique Landscape
{
	pass Pass0
	{   
		//FillMode = WIREFRAME;
		VertexShader = compile vs_2_0 LandscapeVS();
		PixelShader  = compile ps_2_0 LandscapePS();
	}
}